package mid

/*
* @author: hjz
* @time: 2025/6/5 22:20
* @desc:238. 除自身以外数组的乘积
 */
func productExceptSelf(nums []int) []int {
	re1 := make([]int, len(nums))
	re2 := make([]int, len(nums))
	re1[0] = 1
	re2[len(nums)-1] = 1
	for i := 1; i < len(nums); i++ {
		re1[i] = re1[i-1] * nums[i-1]
	}
	for i := len(nums) - 2; i >= 0; i-- {
		re2[i] = re2[i+1] * nums[i+1]
	}
	res := make([]int, len(nums))
	for i := 0; i < len(nums); i++ {
		res[i] = re1[i] * re2[i]
	}
	return res
}
